package com.red.pojo;


import lombok.Data;

@Data
public class Page {
    private int records;
    private int current;
    private int size;
    private int pages;

    public Page(int records, int current, int size) {
        this.records = records;
        this.size = size;
        this.pages = (int) Math.ceil(records / (double) size);

        // 页数超过总页数返回第一页
        // 页数低于 1 返回最大页数
        if (current > pages) {
            this.current = 1;
        } else if (current < 1) {
            this.current = pages;
        } else {
            this.current = current;
        }

    }

}
